<?php 
class User extends DataMapper{
    
    var $validation = array(
        'nome' => array(
            'label' => 'Nome',
            'rules' => array('required', 'trim', 'min_length' => 3, 'max_length' => 20),
        ),
        'usuario' => array(
            'label' => 'Usuario',
            'rules' => array('required', 'min_length' => 6),
        ),
        'senha' => array(
            'label' => 'Senha',
            'rules' => array('required', 'min_length' => 6, 'encrypt'),
        ),
        'confirm_senha' => array(
            'label' => 'Confirmar Senha',
            'rules' => array('required', 'encrypt', 'matches' => 'senha'),
        )
    );
    
    
    function _encrypt($field)
    {
        // Don't encrypt an empty string
        if (!empty($this->{$field}))
        {
            // Generate a random salt if empty
            if (empty($this->salt))
            {
                $this->salt = md5(uniqid(rand(), true));
            }

            $this->{$field} = sha1($this->salt . $this->{$field});
        }
    }
}
?>